/// 访客实体
class VisitorEntity {
  final String visitorId;
  final String targetUserId;
  final String visitorName;
  final String visitorAvatar;
  final DateTime visitTime;

  const VisitorEntity({
    required this.visitorId,
    required this.targetUserId,
    required this.visitorName,
    required this.visitorAvatar,
    required this.visitTime,
  });

  /// 从JSON创建访客对象
  factory VisitorEntity.fromJson(Map<String, dynamic> json) {
    return VisitorEntity(
      visitorId: json['visitorId'] as String,
      targetUserId: json['targetUserId'] as String,
      visitorName: json['visitorName'] as String,
      visitorAvatar: json['visitorAvatar'] as String,
      visitTime: DateTime.parse(json['visitTime'] as String),
    );
  }

  /// 转换为JSON
  Map<String, dynamic> toJson() {
    return {
      'visitorId': visitorId,
      'targetUserId': targetUserId,
      'visitorName': visitorName,
      'visitorAvatar': visitorAvatar,
      'visitTime': visitTime.toIso8601String(),
    };
  }

  /// 复制访客对象并修改部分属性
  VisitorEntity copyWith({
    String? visitorId,
    String? targetUserId,
    String? visitorName,
    String? visitorAvatar,
    DateTime? visitTime,
  }) {
    return VisitorEntity(
      visitorId: visitorId ?? this.visitorId,
      targetUserId: targetUserId ?? this.targetUserId,
      visitorName: visitorName ?? this.visitorName,
      visitorAvatar: visitorAvatar ?? this.visitorAvatar,
      visitTime: visitTime ?? this.visitTime,
    );
  }

  @override
  String toString() {
    return 'VisitorEntity(visitorId: $visitorId, targetUserId: $targetUserId, visitorName: $visitorName, visitTime: $visitTime)';
  }

  @override
  bool operator ==(Object other) {
    if (identical(this, other)) return true;
    return other is VisitorEntity &&
        other.visitorId == visitorId &&
        other.targetUserId == targetUserId;
  }

  @override
  int get hashCode => visitorId.hashCode ^ targetUserId.hashCode;
}
